package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysRoleQueryRequest;
import com.pine.common.beans.pineframework.request.SysRoleSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysRoleQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.common.convertor.SaveConvertor;
import com.pine.dao.pineframework.constants.DataScopeEnum;
import com.pine.dao.pineframework.constants.StatusEnum;
import com.pine.dao.pineframework.entity.SysRole;
import com.pine.manager.pineframework.bo.SysRoleBo;
import com.pine.manager.pineframework.query.SysRoleQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 角色表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysRoleConvertor implements EntityConvertor<SysRole, SysRoleBo>,
        QueryConvertor<SysRoleBo, SysRoleQuery, SysRoleQueryRequest, SysRoleQueryResponse>,
        SaveConvertor<SysRoleBo, SysRoleSaveOrUpdateRequest> {

    @Override
    public abstract SysRole entityBoToEntity(SysRoleBo sysRoleBo);

    @Override
    public abstract SysRoleBo entityToEntityBo(SysRole sysRole);

    @Override
    public abstract SysRoleQueryResponse entityBoToQueryResponse(SysRoleBo sysRoleBo);

    @Override
    public abstract SysRoleQuery queryRequestToQuery(SysRoleQueryRequest queryRequest);


    @Override
    public abstract List<SysRole> entityBoToEntity(List<SysRoleBo> entityBo);

    @Override
    public abstract List<SysRoleBo> entityToEntityBo(List<SysRole> entity);

    @Override
    public abstract SysRoleBo saveRequestToEntityBo(SysRoleSaveOrUpdateRequest sysRoleSaveOrUpdateRequest);

    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysRole sysRole, SysRoleBo sysRoleBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysRoleBo sysRoleBo, SysRole sysRole) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysRoleQuery sysRoleQuery, SysRoleQueryRequest sysRoleQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysRoleQueryResponse sysRoleQueryResponse, SysRoleBo sysRoleBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    public DataScopeEnum integerToDataScopeEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return DataScopeEnum.of(code);
    }

    public Integer dataScopeEnumToInteger(DataScopeEnum dataScopeEnum) {
        if (Objects.isNull(dataScopeEnum)) {
            return null;
        }
        return dataScopeEnum.getCode();
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }
}
